<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据传递测试</title>
</head>
<body>
    <h1>数据传递测试页面</h1>
    
    <div>
        <h2>1. 模拟表单提交数据</h2>
        <button onclick="saveTestData()">保存测试数据到sessionStorage</button>
        <button onclick="loadTestData()">从sessionStorage加载数据</button>
    </div>
    
    <div>
        <h2>2. 当前sessionStorage数据</h2>
        <pre id="currentData"></pre>
    </div>
    
    <div>
        <h2>3. 解析后的数据</h2>
        <pre id="parsedData"></pre>
    </div>

    <script>
        // 模拟表单提交时的数据保存
        function saveTestData() {
            const testData = {
                elderlyNo: 'COUT' + Date.now().toString().slice(-4),
                elderlyName: '黄老十七',
                elderlyIdCard: '110101193805180032',
                contact: '13933914348',
                feePeriod: '2025-10-11 至 2026-10-11',
                careLevel: '等级17',
                bedNumber: 'B051',
                contract: '老人十七合同',
                consultant: 'user04',
                caregiver: 'user04',
                checkoutDate: '2025-10-23',
                checkoutReason: '服务不周',
                remark: '121212',
                applicantName: 'user04',
                submitTime: new Date().toLocaleString('zh-CN', {
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit',
                    hour: '2-digit',
                    minute: '2-digit',
                    second: '2-digit',
                    hour12: false
                }).replace(/\//g, '-'),
                businessId: Date.now(),
                elderlyId: 1,
                checkInManagementId: 1,
                bedId: 1
            };
            
            console.log('保存测试数据:', testData);
            sessionStorage.setItem('checkout_approval_data', JSON.stringify(testData));
            alert('测试数据已保存到sessionStorage');
            loadTestData();
        }
        
        // 模拟审批页面加载数据
        function loadTestData() {
            const rawData = sessionStorage.getItem('checkout_approval_data');
            document.getElementById('currentData').textContent = rawData || '无数据';
            
            if (rawData) {
                try {
                    const data = JSON.parse(rawData);
                    document.getElementById('parsedData').textContent = JSON.stringify(data, null, 2);
                    console.log('解析后的数据:', data);
                } catch (error) {
                    document.getElementById('parsedData').textContent = '解析失败: ' + error.message;
                    console.error('解析数据失败:', error);
                }
            } else {
                document.getElementById('parsedData').textContent = '无数据可解析';
            }
        }
        
        // 页面加载时自动加载数据
        window.onload = function() {
            loadTestData();
        };
    </script>
</body>
</html>
